<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class language_controller extends admin_controller
{
    // Get list
    public function __construct()
    {
        parent::__construct();
        $this->page_title = 'Ngôn ngữ';
        $this->table_name = 'language';
        $this->route_name = 'language';
        $this->business_model = $this->language_model;
    }

    public function get_post_data()
    {
        $post_data = array(
            'desc_en' => $this->input->post('desc_en'),
            'desc_vi' => $this->input->post('desc_vi'),
            'code' => $this->input->post('code')
        );
        return $post_data;
    }

    public function get_list()
    {
        $list = array();
        $news = $this->business_model->get_elements();
        foreach($news as $item)
        {
            $actions = array();
            $actions[] = array(
                'text' => 'Sửa',
                'href' => base_url(). $this->base_admin_url .$this->route_name.'/update/'.$item->id
            );
            $list[] = array(
                'can_delete' => $item->id,
                'code' => $item->code,
                'desc_en' => $item->desc_en,
                'desc_vi' => $item->desc_vi,
                'actions' => $actions
            );
        }
        return $list;
    }

    public function get_header_list()
    {
        $list = array();
        $list[] = 'Code';
        $list[] = 'Anh';
        $list[] = 'Việt';
        $list[] = 'Công việc';
        return $list;
    }

    public function get_fields($id)
    {
        if($id == -1)
        {
            $model = new stdClass();
            $model->desc_en = '';
            $model->desc_vi = '';
            $model->code = '';
        }
        else
        {
            $model = $this->business_model->get_element_by_id($id);
        }
        $fields = array();
        $fields[] = array(
            'text' => 'Code',
            'name' => 'code',
            'value' => $model->code,
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Anh',
            'name' => 'desc_en',
            'value' => $model->desc_en,
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Việt',
            'name' => 'desc_vi',
            'value' => $model->desc_vi,
            'type' => 'text'
        );
        return $fields;
    }
}